function u=utility_f(states,xadata,fixedparms,spec)
% create payoff matrix for each terminal action in each state

     % preference coeficients
    i=fixedparms.n_groomchars;
    beta_groom=[1 fixedparms.prefparms(2:i)];
    j=1+fixedparms.n_prefparms;

    beta_rest=[fixedparms.prefparms(i+1:j)];

    % set up utility look-up matrix
    %------------------------------
    % columns are: bad groom, good groom

     % take the preferences over groom types and divide grooms into good and
    % bad grooms as above and below median
    %-----------------------------------------------
    groom_qual=xadata.G_exante.*beta_groom;
    groom_qual=sum(groom_qual,2);
    good_groom=xadata.G_exante(:,1);

    u=zeros(size(states,1),2);
    u(:,1)=mean(groom_qual(good_groom==0));
    u(:,2)=mean(groom_qual(good_groom==1));
    
     if spec==2
            u(:,1)=u(:,1)+beta_rest(1).*fixedparms.ind_likeschool.*(states(:,2)-7);
            u(:,2)=u(:,2)+beta_rest(1).*fixedparms.ind_likeschool.*(states(:,2)-7);
          
            age_ed_comp=beta_rest(2).*(states(:,1))+ ...
                        beta_rest(3).*(states(:,1)>17).*(states(:,1)-18)+ ...
                        beta_rest(4).*(states(:,2)-7)+ ...
                        beta_rest(5).*(states(:,2)==13);
        u(:,1)=u(:,1)+age_ed_comp;
        u(:,2)=u(:,2)+age_ed_comp;

     end

end
